<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />

</head>

<body>

    <div id="task-ing-1">


    </div>
    <div style="text-align:center;margin:10px;display:none;background:#fff;padding:20px;" id="default-1">
      <img src="./img/muyou.png" style="display:inline;">
        <p><span style="font-size:20px;">亲,</span>&nbsp;&nbsp;&nbsp;&nbsp;您当前木有对应的试用品</p>
    </div>

</body>
<script type="text/template" id="template1">
    {{~it:value:index}}
    <ul class="aui-list aui-media-list" style="margin-bottom:0.225rem;" onclick="fnRecover(this)">

        <li class="aui-list-item">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media" style="width:8rem;height:8rem">
                    <img src="{{= fnSiteUrl(value.thumb)}}" style="width:8rem;height:8rem">
                </div>
                <div class="aui-list-item-inner" style="width:10rem">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title" style="white-space: nowrap;text-overflow:ellipsis;overflow:hidden;">{{= value.title}}</div>
                    </div>
                    <div class="aui-list-item-text">
                        <p>Id:{{= value.goods_id}}</p>
                        <input type="hidden" class="orderid" value="{{= value.oid}}">
                    </div>
                    <div class="aui-list-item-text">
                        <p>申请: <span>{{=userDate(value.create_time)}}</span></p>
                    </div>
                    <div class="aui-list-item-text">
                        <p>试用价: <span style="color:red">{{= value.agoods_price }}</span></p>
                        <p>返：<span style="color:red">{{= value.agoods_price }}</span></p>

                    </div>
                    <div class="aui-list-item-text">
                        <p>旺号:{{= value.account }}</p>


                    </div>
                    <div class="aui-list-item-text">
                        <p>等级：<img src="{{= fnSiteUrl(value.account_level)}}" alt="" style="display:inline;"></p>
                    </div>
                    <div class="aui-list-item-text">
                        <p>状态:已完成</p>
                        <p style="color:#fff;background:#ff4285;padding:0.125rem;border-radius:5px;">点击操作</p>
                    </div>
                </div>
            </div>
        </li>
    </ul>
    {{~}}
</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>

<script type="text/javascript">
    apiready = function() {
        fnGetData();
        initRefresh();
    };
    //下拉刷新，松开刷新
    function initRefresh() {
        api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
              fnGetData();
        });
    }

    function fnGetData() {
        var userInfo = $api.getStorage('userInfo');

        //获取数据app中存入的数据然后分配到模板中；
        var random = userInfo.random;
        var userid = userInfo.userid;


        api.ajax({
            url: SITE_URL+'index.php?m=api&c=appnew&a=order_apply',
            method: 'post',
            data: {
                values: {
                    userid: userid,
                    random: random,
                    trial: 'trial',
                    state: '4',
                },

            }
        }, function(ret, err) {
        //alert(JSON.stringify(ret));
            switch (ret.status) {
              case 0:
                  alert(ret.msg);
                  break;
                case 1:
            //  alert(1);
                    fnUpdateList(ret);
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    break;
                case 2:
                    alert(ret.msg);
                    api.openWin({
                        name: 'login',
                        url: './login.html',
                        pageParam: {
                            name: 'test'
                        }
                    });

                    //alert(22222222);
                    break;
                case 5:
                    $("#default-1").show();
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    break;
            }
        });
    }
    //更新数据
    function fnUpdateList(ret) {
//alert(2);
        var list = $api.byId('task-ing-1'); //获取节点
        //var str={"array":["banana","apple","orange"]};
        // 1. 编译模板函数
        var tempFn = doT.template($api.byId('template1').innerHTML); //找到模板多次使用
        // 2. 多次使用模板函数
        var resultText = tempFn(ret.data);
        $api.html(list, "");
        $api.append(list, resultText);
        $("#default-1").hide();

    }

    function fnRecover(that) {
        var orderId = $(that).find(".orderid").val();
        api.actionSheet({
            title: '操作',
            buttons: ['操作记录']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            switch (index) {
                case 1:

                    fnOperateLogWin(orderId);
                    break;

            }
        });

    }

    function fnOperateLogWin(orderId) {
        fnGetDataLog(orderId);
    }

    function fnGetDataLog(orderId) {

        var userInfo = $api.getStorage('userInfo');
        //获取数据app中存入的数据然后分配到模板中；
        var random = userInfo.random;
        var userid = userInfo.userid;
        api.ajax({
            url: SITE_URL+'index.php?m=api&c=appnew&a=view_log',
            method: 'POST',
            data: {
                values: {
                    "userid": userid,
                    "random": random,
                    "orderid": orderId,
                }
            }
        }, function(ret, err) {
            if (ret.status == 1) {
                api.openWin({
                    name: "task_operate_log",
                    url: './task_operate_log.html',
                    pageParam: {
                        orderId: orderId
                    }
                });
            } else {
                alert(ret.msg);
            }


        });
    }
</script>

</html>
